package com.rui.equipment.controller;


import com.rui.common.vo.Result;
import com.rui.emp.entity.Emp;
import com.rui.equipment.entity.Equipment;
import com.rui.equipment.service.EquipmentService;
import com.rui.equipment.vo.EquipmentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/equipment")
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;
    @GetMapping("")
    public String toEquipmentUI(){
        return "equipment/equipmentList";
    }
    @GetMapping("/list")
    @ResponseBody
    public Result<Object> getEquipmentList(EquipmentQuery param){
        List<Equipment> list = equipmentService.getEquipmentList(param);//查出员工信息
        Long count = equipmentService.countEquipmentList(param);   //分页
        return Result.success(list, count);
    }
    @PostMapping("")//新增数据时，用post请求
    @ResponseBody
    public Result<Object> addequipment(Equipment equipment){
        equipmentService.addEquipment(equipment);
        return Result.success("添加员工信息成功！");
    }
    @GetMapping("add/ui")
    public String toAddUI(Model model){
        return "equipment/addEquipment";
    }
    @DeleteMapping("/{ids}")
    @ResponseBody
    public Result<Object> delectequipmentByIds(@PathVariable("ids") String ids){
        equipmentService.delectEquipmentByIds(ids);
        return Result.success("删除员工成功");
    }

    @GetMapping("/{id}")
    public String getEmpByid(@PathVariable("id") Integer id,Model model){
        Equipment equipment =  equipmentService.getEquipmentById(id);
        model.addAttribute("equipment",equipment);
        return "equipment/equipmentEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateEquipment( Equipment equipment ){
        equipmentService.updateEquipment(equipment);
        return  Result.success("员工信息修改成功");
    }

}
